package com.iweb.day12;

import java.io.IOException;
import java.net.Socket;

/**
 * @author WuYongheng
 * @date 2021/11/30
 * @description socket通信程序的客户端示例
 */
public class Cilent {
    public static void main(String[] args) throws IOException {
        String serverHost = "127.0.0.1";
        int serverPort = 6666;
        Socket socket = null;
        try {
//            创建与服务器连接的套接字对象
            socket = new Socket(serverHost, serverPort);
            System.out.println("成功与服务器建立连接："+
                    socket.getRemoteSocketAddress());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 慎用！断开与服务器的连接，发送与服务器断开连接的请求
//            socket.close();
        }

    }
}
